package com.bdqn.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * R
 *
 * @author LILIBO
 * @since 2022-02-20
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class R implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private Object data;

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 成功时返回的数据
     *
     * @param data 数据
     * @return
     */
    public static R success(Object data) {
        R success = new R(0, "success", data);
        return success;
    }

    /**
     * 失败时返回的数据
     *
     * @param msg 消息
     * @return
     */
    public static R failure(String msg) {
        R failure = new R(1, msg, null);
        return failure;
    }

}
